﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class SystemManage_EditPassword : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            tbUserName.Text = _Customer.CustomerNO;
        }

        tbOldUserPassword2.Attributes.Add("value", tbOldUserPassword2.Text);
        tbNewUserPassword.Attributes.Add("value", tbNewUserPassword.Text);
        tbNewUserPassword_2.Attributes.Add("value", tbNewUserPassword_2.Text);
        tbNewUserPassword2.Attributes.Add("value", tbNewUserPassword2.Text);
        tbNewUserPassword2_2.Attributes.Add("value", tbNewUserPassword2_2.Text);
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;        
        SecondLevelPassword = true;

        base.OnInit(e);
    }

    #endregion

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (PublicFunction.EncryptPassword(tbOldUserPassword2.Text.Trim()) != _Customer.Password2)
        {
            Shove._Web.JavaScript.Alert(this.Page, "旧二级密码错误！");

            return;
        }

        if (tbNewUserPassword.Text.Trim() == "")
        {
            Shove._Web.JavaScript.Alert(this.Page, "新一级密码不能为空！");

            return;
        }

        if (tbNewUserPassword.Text != tbNewUserPassword_2.Text)
        {
            Shove._Web.JavaScript.Alert(this.Page, "二次输入的新一级密码不一致！");

            return;
        }

        if (tbNewUserPassword2.Text.Trim() == "")
        {
            Shove._Web.JavaScript.Alert(this.Page, "新二级密码不能为空！");

            return;
        }

        if (tbNewUserPassword2.Text != tbNewUserPassword2_2.Text)
        {
            Shove._Web.JavaScript.Alert(this.Page, "二次输入的新二级密码不一致！");

            return;
        }

        string Return = "";
        int ResultValue = 0;

        _Customer.GetCustomerInformationByID(ref Return);

        if(Return!="")
        {
            Shove._Web.JavaScript.Alert(this.Page, Return);

            return;
        }

        string sPWD1= PublicFunction.EncryptPassword(tbNewUserPassword.Text.Trim());
        string sPWD2 = PublicFunction.EncryptPassword(tbNewUserPassword2.Text.Trim());

        DAL.Tables.tbl_Customer Customer = new DAL.Tables.tbl_Customer();
        Customer.Password1.Value=sPWD1;
        Customer.Password2.Value=sPWD2;
        long i = Customer.Update("ID="+_Customer.ID);

        if (i >= 0)
        {
            Shove._Web.JavaScript.Alert(this.Page, "密码修改成功。请妥善保管好您的密码！");
        }

    }
}

